{%extend name="Public:layout"/%}

   {%block name="title"%} 
    <h2 class="mb20">
      目录管理
    </h2>
   {%/block%}
   {%block name="contents"%}  
    <div class="heading clearfix">
      <div class="pull-left">
        <form class="form-inline" onsubmit="return false;" stverify="true" method="get" action="">
          <select class="st-dropdown" name="menuM_id" id="option" data-config="onChange:ST.loadSubOption">
            <option value="0">所有</option>
           {%notempty name="menuMainList"%}
            {%foreach name="menuMainList" item="vo"%}            
            <option value="{%$vo.class_id%}" 
                 {%if condition="$menuM_id eq $vo['class_id']" %} selected {%/if%}>{%$vo.name%}</option>
            {%/foreach%}
           {%/notempty%}
          </select>
          <select class="st-dropdown" name="menuS_id" id="suboption" >
            <option value="0">所有</option>
           {%notempty name="menuSubList"%}
            {%foreach name="menuSubList" item="vo"%}            
            <option value="{%$vo.class_id%}"
                 {%if condition="$menuS_id eq $vo['class_id']" %} selected {%/if%}>{%$vo.name%}</option>
            {%/foreach%}
           {%/notempty%}
          </select>
          <input type="submit" class="btn" value="搜索">
        </form>
      </div>
      <div class="pull-right">
          <div class="alert alert-error"><div class="alert-inner">一级目录</div></div>
          <div class="alert alert-info"><div class="alert-inner">二级目录</div></div>
          <div class="alert alert-warning"><div class="alert-inner">三级目录</div></div>
        <a title="添加目录" href="javascript:;" onclick="ST.todo('add','0')" class="btn mr5"><i class="icon i-add"></i> 添加目录</a>
      </div>
    </div>
    <table class="table table-listing table-hovered">
      <thead class="thead-gray">
      <tr>
        <th>编号</th>
        <th>目录所属 ：排序编号</th>
        <th>名称</th>
        <th>管理</th>
      </tr>
      </thead>
      <tbody>      
          
    {%notempty name="menuMList"%}
      {%foreach name="menuMList" item="vo" %}
       {%if condition="strlen($vo['class_id']) eq 2"%}
      <tr style="background-color: #ffdce8; font-size: 14px;">
      {%/if%}
      {%if condition="strlen($vo['class_id']) eq 4"%}
      <tr style="background-color: #d8eaff; font-size: 13px;">
      {%/if%}
        <td>{%$vo.id%}</td>
        <td>
           <span title="{%$vo.className%}"> {%$vo.name%} </span> ：{%$vo.orderby%}
        </td>
        <td>
          {%$vo.name%}
        </td>
        <td>
          <a href="javascript:;" title="编辑目录" onclick="ST.todo('edit','{%$vo.id%}')"><i class="icon i-edit"></i></a>
          <a href="javascript:;" title="删除目录" onclick="ST.todo('del','{%$vo.id%}')"><i class="icon i-del"></i></a>
          <a href="javascript:;" title="添加下级目录" onclick="ST.todo('add','{%$vo.class_id%}')"><i class="icon i-add"></i></a>
          {%if condition="$vo['minSort']" %}
                <i class="icon i-sortup disabled" title="已经是最顶部"></i>
          {%else/%}
                <a href="javascript:;" title="提升排序" onclick="ST.todo('sortMenu','{%$vo.id%}','up')"><i class="icon i-sortup"></i></a>
          {%/if%}
          {%if condition="$vo['maxSort']"%}
                <i class="icon i-sortdown disabled" title="已经是最底部"></i>
           {%else/%}
                <a href="javascript:;" title="降低排序" onclick="ST.todo('sortMenu','{%$vo.id%}','down')"><i class="icon i-sortdown"></i></a>
           {%/if%}
        </td>
      </tr>
        {%notempty name="menuSList[$vo['class_str']]"%}
          {%foreach name="menuSList[$vo['class_str']]" item="vos" %}
                {%if condition="strlen($vos['class_id']) eq 4"%}
                <tr style="background-color: #d8eaff; font-size: 13px;">
                {%/if%}
                {%if condition="strlen($vos['class_id']) eq 6"%}
                <tr style="background-color: #fffff4; ">
                {%/if%} 
                  <td>{%$vos.id%}</td>
                  <td>
                   &nbsp; &nbsp;└  <span title="{%$vos.className%}"> {%$vos.name%} </span> ： {%$vos.orderby%}
                  </td>
                  <td>
                    {%$vos.name%}
                  </td>
                  <td>
                    <a href="javascript:;" title="编辑目录" onclick="ST.todo('edit','{%$vos.id%}')"><i class="icon i-edit"></i></a>
                    <a href="javascript:;" title="删除目录" onclick="ST.todo('del','{%$vos.id%}')"><i class="icon i-del"></i></a>
                    <a href="javascript:;" title="添加下级目录" onclick="ST.todo('add','{%$vos.class_id%}')"><i class="icon i-add"></i></a>
                    
                   {%if condition="$vos['minSort']" %}
                         <i class="icon i-sortup disabled" title="已经是最顶部"></i>
                   {%else/%}
                         <a href="javascript:;" title="提升排序" onclick="ST.todo('sortMenu','{%$vos.id%}','up')"><i class="icon i-sortup"></i></a>
                   {%/if%}
                   {%if condition="$vos['maxSort']"%}
                         <i class="icon i-sortdown disabled" title="已经是最底部"></i>
                    {%else/%}
                         <a href="javascript:;" title="降低排序" onclick="ST.todo('sortMenu','{%$vos.id%}','down')"><i class="icon i-sortdown"></i></a>
                    {%/if%}
                  </td>
                </tr>                
                {%notempty name="menuSList[$vos['class_str']]"%}
                  {%foreach name="menuSList[$vos['class_str']]" item="voss" %}
                        {%if condition="strlen($voss['class_id']) eq 6"%}
                        <tr style="background-color: #fffff4;">
                        {%/if%} 
                          <td>{%$voss.id%}</td>
                          <td>
                            &nbsp; &nbsp; &nbsp; &nbsp; └   <span title="{%$voss.className%}"> {%$voss.name%} </span> ： {%$voss.orderby%}
                          </td>
                          <td>
                            {%$voss.name%}
                          </td>
                          <td>
                            <!--<a href="javascript:;" title="添加下级目录" onclick="ST.todo('add','{$voss.class_id}')"><i class="icon i-add"></i></a>-->
                            <a href="javascript:;" title="编辑目录" onclick="ST.todo('edit','{%$voss.id%}')"><i class="icon i-edit"></i></a>
                            <a href="javascript:;" title="删除目录" onclick="ST.todo('del','{%$voss.id%}')"><i class="icon i-del"></i></a>
                            <i class="icon i-add disabled" title="最多只能添加三级菜单">&nbsp;</i>
                             {%if condition="$voss['minSort']" %}
                                    <i class="icon i-sortup disabled" title="已经是最顶部"></i>
                              {%else/%}
                                    <a href="javascript:;" title="提升排序" onclick="ST.todo('sortMenu','{%$voss.id%}','up')"><i class="icon i-sortup"></i></a>
                              {%/if%}
                              {%if condition="$voss['maxSort']"%}
                                   <i class="icon i-sortdown disabled" title="已经是最底部"></i>
                               {%else/%}
                                   <a href="javascript:;" title="降低排序" onclick="ST.todo('sortMenu','{%$voss.id%}','down')"><i class="icon i-sortdown"></i></a>
                               {%/if%}
                          </td>
                        </tr>
                {%/foreach%}
               {%/notempty%}
        {%/foreach%}
       {%/notempty%}
    {%/foreach%}
   {%/notempty%}
      </tbody>
    </table>
    <div class="clearfix mt10">
      <div class="pull-right">
        <div class="pagination"></div>
      </div>
    </div>
   {%/block%}

{%block name="js"%}     
<script>
  $.extend(ST.ACTION, {
    'del': "{%:U('/admin/admin/delmenu')%}",//删除目录action地址
    'add': "{%:U('/admin/admin/savemenu')%}",//添加目录弹窗地址
    'edit': "{%:U('/admin/admin/savemenu')%}",//编辑目录弹窗地址
    'loadSub': "{%:U('/admin/admin/ajaxgetatomsub')%}",//读取子选项地址
    'sortMenu': "{%:U('/admin/admin/sortmenu')%}"//向上向下排序
  });
  $.extend(ST, {
    todoList: function () {

    },
    /**
     * 弹出添加窗口
     * @param id      数据id
     */
    add: function (id) {
      ST.editBox(ST.ACTION.add + '/id/' + id, {
        title: '添加目录',
        height: 500
      });
    },
    /**
     * 弹出编辑窗口
     * @param id      数据id
     */
    edit: function (id) {
      ST.editBox(ST.ACTION.edit + '/id/' + id, {
        title: '编辑目录',
        height: 500
      });
    },
    /**
     * 执行AJAX删除操作后刷新页面
     * @param id      数据id
     */
    del: function (id) {
      ST.execAJAX({
        url: ST.ACTION.del,     //服务端请求地址
        params: {id: id},       //发送到服务端的参数（如：{myparam:1}）
        massage: '确定删除吗？',       //提示信息（仅hasconfirm为true时有用）
        hasconfirm: true,       //提交前是否显示确认框
        succFun: function (j) {  //成功后的回调方法：刷新页面
          if (!j) return;
          if (j.data && j.data.url) {
            location.href = j.data.url;
          } else {
            ST.reload();
          }
        }
      });
      //更多选项参见common.js execAJAX方法
    },   
    sortMenu: function (id,type) {
      ST.execAJAX({
        url: ST.ACTION.sortMenu,
        params: {id: id,type:type},       //发送到服务端的参数（如：{myparam:1}）
        massage: '确定排序？',       //提示信息（仅hasconfirm为true时有用）
        hasconfirm: false,       //提交前是否显示确认框
        succFun: function (j) {  //成功后的回调方法：刷新页面
          if (!j) return;
          if (j.data && j.data.url) {
            location.href = j.data.url;
          } else {
            ST.reload();
          }
        }
      });
      //更多选项参见common.js execAJAX方法
    }
  });
  ST.init();
</script>
{%/block%}